package eo.builder.property;

import org.hibernate.EntityMode;
import org.hibernate.metadata.ClassMetadata;
import org.hibernate.type.Type;

import eo.descriptor.property.impl.AbstractPropertyDescriptor;

public class HibernateMetaClassPropertyDescriptor extends
        AbstractPropertyDescriptor {

    private final ClassMetadata metaData;
    private final Type propertyType;

    public HibernateMetaClassPropertyDescriptor(Class<?> containerClass,
            String name, ClassMetadata metaData) {
        super(containerClass, name);
        this.metaData = metaData;
        propertyType = this.metaData.getPropertyType(name);
    }

    public final Object getValue(Object entity) {
        return this.metaData.getPropertyValue(entity, this.getName(),
                EntityMode.POJO);
    }

    @Override
    public boolean isAssociation() {
        return this.propertyType.isAssociationType();
    }

    @Override
    public boolean isMany() {
        return this.propertyType.isCollectionType();
    }

    @Override
    public boolean isEmbedded() {
        return this.propertyType.isComponentType();
    }

}
